import {
  Controller,
  Get,
  Post,
  Delete,
  Param,
  UseGuards,
  Request,
} from '@nestjs/common';
import { FavoritesService } from './favorites.service';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';

/**
 * 收藏控制器
 */
@Controller('favorites')
@UseGuards(JwtAuthGuard)
export class FavoritesController {
  constructor(private readonly favoritesService: FavoritesService) {}

  /**
   * 获取当前用户的收藏列表
   */
  @Get()
  findByUser(@Request() req) {
    return this.favoritesService.findByUser(req.user.id);
  }

  /**
   * 添加收藏
   */
  @Post(':toolId')
  add(@Request() req, @Param('toolId') toolId: string) {
    return this.favoritesService.add(req.user.id, +toolId);
  }

  /**
   * 取消收藏
   */
  @Delete(':toolId')
  remove(@Request() req, @Param('toolId') toolId: string) {
    return this.favoritesService.remove(req.user.id, +toolId);
  }

  /**
   * 检查是否已收藏
   */
  @Get('check/:toolId')
  async checkFavorite(@Request() req, @Param('toolId') toolId: string) {
    const isFavorited = await this.favoritesService.isFavorited(req.user.id, +toolId);
    return { isFavorited };
  }
}





